<?php
    $url = new Url();
    $arr_tip_icon = LoadConfig::$arr_tip_icon;
    $current_url = Common::getCurrentUrl();

?>
<script type="text/javascript">
    function ajaxQuickUpdate(id){
        var strUrl = "<?=$url->createUrl("tips/ajaxQuickUpdate") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                color:$("#color_"+id).val(),
                icon:$("input[name=icon_"+id+"]:checked").val(),
                button:$("input[name=button_"+id+"]:checked").val(),
                id:id
            },
            success: function(msg){
                if(msg == 1){
                    alert('Sửa thành công');
                    location.reload();
                }else{
                    alert(msg);
                }
            }          
        });
    }
    function ajaxDelete(id){
        var strUrl = "<?=$url->createUrl("tips/ajaxDelete") ?>";
        if(confirm('Bạn có chắc chắn muốn xóa không ?')){
            $.ajax({
                type: "POST",
                url: strUrl,
                data: {
                    id:id
                },
                success: function(msg){
                    if(msg == 1){
                        alert('Xóa thành công');
                        location.reload();
                    }else{
                        alert(msg);
                    }
                }          
            });
        }
    }
</script>
<div class="main clearfix">
    <div class="box">
        <div class="fillter clearfix">
            <div class="fl">
                <a href="<?php echo $url->createUrl("tips/create")?>"><input type="button" class="btn-bigblue" value=" Thêm mới "></a>
            </div>
        </div>
        <div class="table clearfix">
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
                <tbody>
                    <tr class="bg-grey">
                        <td width="4%"><strong>ID</strong></td>
                        <td width="20%"><strong>Tiêu đề</strong></td>
                        <td width="20%"><strong>Link </strong></td>
                        <td width="5%"><strong>Thứ tự </strong></td>
                        <td width="5%"><strong>Loại </strong></td>
                        <td width="20%"><strong>Hiển thị </strong></td>
                        <td width="8%"><strong>Ngày tạo</strong></td>
                        <td width="13%"><strong>Hành động</strong></td>
                    </tr>
                    <?php foreach($data as $key=>$value){
                            if($value["icon"] >0) 
                                $icon_tip = '<img src="'.Yii::app()->params["static_url_cp"].'/images/'.$arr_tip_icon[$value["icon"]].'"/>';
                            else
                                $icon_tip = "None";
                        ?>
                        <tr>
                            <td><?php echo $value["id"];?></td>  
                            <td><?php echo $value["title"];?></td>  
                            <td><?php echo $value["url"];?></td>  
                            <td><?php echo $value["position"];?></td>  
                            <td><?php echo intval($value["type"])==1 ? 'Hướng dẫn quy định':'Bình thường';?></td>
                            <td>
                                <div class="clearfix">
                                    <div class="fl">
                                        <select id="color_<?php echo $value["id"]?>">
                                            <?php foreach(LoadConfig::$arr_tip_color as $key_color=>$value_color){?>
                                                <option value="<?php echo $key_color;?>" <?php echo $key_color==$value["color"] ? 'selected="selected"':'';?>><?php echo $value_color;?></option>
                                                <?php }?>
                                        </select>
                                    </div>
                                    <div class="opt-color fr"><span class="<?php echo $value["color"];?>"></span></div>
                                </div>
                                <p class="opt-icon">
                                    <?php foreach(LoadConfig::$arr_tip_icon as $key_icon=>$value_icon){ 
                                        ?>
                                        <input name="icon_<?php echo $value["id"]?>" type="radio" value="<?php echo $key_icon;?>" <?php echo $key_icon==$value["icon"] ? 'checked="checked"':'';?>>
                                        <?php if($key_icon >0){ ?>                                        
                                            <img src="<?php echo Yii::app()->params["static_url_cp"].'/images/'.$value_icon ?>"/>
                                            <?php }else{?>
                                            None!
                                            <?php }?>
                                        <?php }?>

                                </p>
                                <p class="opt-icon">
                                    <?php foreach(LoadConfig::$button_tips as $key_button=>$value_button){ 
                                        ?>
                                        <input name="button_<?php echo $value["id"]?>" type="radio" value="<?php echo $key_button;?>" <?php echo $key_button==$value["button"] ? 'checked="checked"':'';?>>
                                        <?php if($key_button >0){ ?>                                        
                                            <img src="<?php echo Yii::app()->params["static_url_cp"].'/images/'.$value_button ?>"/>
                                            <?php }else{?>
                                            None!
                                            <?php }?>
                                        <?php }?>

                                </p>
                            </td>
                            <td><?php echo date('d-m-Y H:i:s',$value["create_date"]);?></td> 
                            <td>
                                <a class="s14" href="javascript:void(0)" onclick="ajaxQuickUpdate('<?php echo $value["id"]?>')"> Lưu </a> | 
                                <a href="<?php echo $url->createUrl("tips/edit",array("id"=>$value["id"]))?>">Sửa</a>  |
                                <a href="javascript:void(0)" onclick="ajaxDelete('<?php echo $value["id"];?>')">Xóa</a>
                            </td>
                        </tr>
                        <?php }?>
                </tbody>
            </table>
        </div>
    </div>
</div>